package com.woniu.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.project.core.dto.ResultDto;
import com.woniu.project.dto.productentitydto.ProductEntityDto;
import com.woniu.project.dto.productentitydto.ProductEntityListDto;
import com.woniu.project.dto.productentitydto.ProductEntityOneDto;
import com.woniu.project.params.productentityparams.ProductEntityConditionParams;
import com.woniu.project.params.productentityparams.ProductEntityParams;
import com.woniu.project.service.IProductEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author WHF
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/product-entity")
@Slf4j
@Api(tags = "productEntity控制层")
public class ProductEntityController {

    @Autowired
    private IProductEntityService productEntityService;

    /**
     * 查询商品实体列表
     * @param productEntityConditionParams
     * @return
     */
    @ApiOperation(value = "查询商品实体列表",notes = "必填项无")
    @GetMapping("selectProductEntityList")
    public ResultDto selectProductEntityList(ProductEntityConditionParams productEntityConditionParams){
        log.info("查询商品列表时传入的条件列表:{}",productEntityConditionParams);
        IPage<ProductEntityListDto> productEntityListDtoIpage=productEntityService.selectProductEntityList(productEntityConditionParams);

        return ResultDto.success(productEntityListDtoIpage);
    }

    /**
     * 根据id查询单个商品详细信息
     * @param productEntityId productEntityId商品实体id
     * @return
     */
    @ApiOperation(value = "查询单个商品实体详情",notes = "无")
    @GetMapping("selectOneProductEntity/{productEntityId}")
    public ResultDto selectOneProductEntity(@PathVariable("productEntityId") Integer productEntityId){
        log.info("查询商品详情时传入的商品实体id:{}",productEntityId);
        ProductEntityOneDto productEntityOneDto = productEntityService.selectOneProductEntity(productEntityId);
        return ResultDto.success(productEntityOneDto);
    }

    /**
     * 新增/修改商品实体
     * @param productEntityParams productEntityParams商品实体对象
     * @return
     */
    @ApiOperation(value = "新增/修改的商品实体",notes = "必填项无")
    @PostMapping("updateProductEntity")
    public ResultDto updateProductEntity(@RequestBody ProductEntityParams productEntityParams){
        log.info("要新增/修改的商品对象为:{}",productEntityParams);
        productEntityService.updateProductEntity(productEntityParams);
        return ResultDto.success(200,"新增/修改成功",null);
    }

    /**
     * 根据商品实体id删除商品
     * @param productEntityId 商品实体id
     * @return
     */
    @ApiOperation(value = "删除商品实体",notes = "无")
    @DeleteMapping("deleteProductEntity/{productEntityId}")
    public ResultDto deleteProductEntity(@PathVariable("productEntityId") Integer productEntityId){
        log.info("删除商品时传入的商品实体id:{}",productEntityId);
        productEntityService.deleteProductEntity(productEntityId);
        return ResultDto.success(200,"删除成功",null);
    }

    /**
     * 根据商品属性id查询商品实体
     * @param propertyId 商品属性id
     * @return
     */
    @ApiOperation(value = "根据商品属性查询商品实体",notes = "无")
    @GetMapping("selectByPropertyId/{propertyId}")
    public ResultDto selectByPropertyId(@PathVariable("propertyId") Integer propertyId){
        log.info("查询商品实体时传入的商品属性id:{}",propertyId);
        List<ProductEntityDto> productEntityDtos=productEntityService.selectByPropertyId(propertyId);
        return ResultDto.success(productEntityDtos);
    }


    /**
     * 根据大商品类别id查询商品
     * @param bigTypeId 大类id
     * @return
     */
    @ApiOperation(value = "根据商品大类查询商品实体",notes = "无")
    @GetMapping("selectByBigTypeId/{bigTypeId}")
    public ResultDto selectByBigTypeId(@PathVariable("bigTypeId") Integer bigTypeId){
        log.info("查询商品实体时传入的大类id:{}",bigTypeId);
        List<ProductEntityDto> productEntityDtos=productEntityService.selectByBigTypeId(bigTypeId);
        return ResultDto.success(productEntityDtos);
    }


    /**
     * 根据小商品类别id查询商品
     * @param smallTypeId 小类别
     * @return
     */
    @ApiOperation(value = "根据商品小类查询商品实体",notes = "无")
    @GetMapping("selectBySmallTypeId/{smallTypeId}")
    public ResultDto selectBySmallTypeId(@PathVariable("smallTypeId") Integer smallTypeId){
        log.info("查询商品实体时传入的小类id:{}",smallTypeId);
        List<ProductEntityDto> productEntityDtos=productEntityService.selectBySmallTypeId(smallTypeId);
        return ResultDto.success(productEntityDtos);
    }

    /**
     * 根据商品id查询商品实体
     * @param productId 商品id
     * @return
     */
    @ApiOperation(value = "根据商品查询商品实体",notes = "无")
    @GetMapping("selectByProductId/{productId}")
    public ResultDto selectByProductId(@PathVariable("productId") Integer productId){
        log.info("查询商品实体时传入的商品id:{}",productId);
        List<ProductEntityDto> productEntityDtos=productEntityService.selectByProductId(productId);
        return ResultDto.success(productEntityDtos);
    }

    /**
     * 根据商品品牌查询商品实体
     * @param brandId 品牌id
     * @return
     */
    @ApiOperation(value = "根据商品品牌查询商品实体",notes = "无")
    @GetMapping("selectByBrandId/{brandId}")
    public ResultDto selectByBrandId(@PathVariable("brandId") Integer brandId){
        log.info("查询商品实体时传入的商品品牌id:{}",brandId);
        List<ProductEntityDto> productEntityDtos=productEntityService.selectByBrandId(brandId);
        return ResultDto.success(productEntityDtos);
    }
}

